package youth;

public class Draw {
    private int height;
    // 构造函数，初始化高度
    public Draw(int h) {
        height = h;
    }
    //绘制三角形
public void drawsanjiaoxing(){
    for(int i=1;i<=height;++i){
        for(int j=0;j<height-i;++j){
            System.out.println("");
        }
        for(int k=0;k<2*i-1;++k){
            System.out.println("*");
        }
        System.out.println();
    }
}
   //绘制矩形
public void drawjuxing(){
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < height; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
    //绘制正方形
    public void drawZhengfangxing() {
        drawjuxing();
    }
    // 绘制平行四边形
    public void drawPingxingsibianxing() {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < i; j++) {
                System.out.print(" ");
            }
            for (int k = 0; k < height; k++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    public static void main(String[] args) {
        // 创建Draw类对象，高度设为9
        Draw myDraw = new Draw(9);

        System.out.println("绘制三角形：");
        myDraw.drawsanjiaoxing();
        System.out.println("绘制矩形：");
        myDraw.drawjuxing();
        System.out.println("绘制正方形：");
        myDraw.drawZhengfangxing();
        System.out.println("绘制平行四边形：");
        myDraw.drawPingxingsibianxing();
    }
}